<?php
/**
 * Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 */
class BlogBaseController extends Controller
{
    /**
     * @var string the default layout for the controller view. Defaults to '//layouts/column1',
     * meaning using a single column layout. See 'protected/views/layouts/column1.php'.
     */
     
    // 
    public $layout    = '//blog/blog_column'; 
    public $themeName = 'zbench'; 

    // 
    public $menus;
    
    // locale manager
    public $locale;

    // url manager
    public $url;
    
    // 分頁管理
    public $pageLimit = null;

    // 權限管理
    //public $permissionManager = null;

    /*
    */
    function init()
    {
        parent::init();

        $this->initDb();

        // base load
        //$dateManager = new DateManager();
        $this->locale = new LocaleManager();
        $this->locale->loadLocale();
        $this->url = new UrlManager( $this ); // $this is controller  

        //
        /*
        $this->permissionManager = new PermissionManager();
        $this->permissionManager->setSessionManager( new SessionManager() );
        */
    }

    function beforeAction($action)
    {
        //parent::beforeAction($action);


        // check user identities
        /*
        $user = SessionManager::getUser();
        if( !$user ) {
            Request::redirect('member/');
            //Request::redirect('member/index');
        }
        */

        //
        SessionManager::clearTopMessages();

        return true;
    }

    function afterAction($action)
    {
        return true;
    }

    // --------------------------------------------------------------------------------
    //
    // --------------------------------------------------------------------------------

    // template base path
    public function getTemplatePath( $templateName=null, $pathType=null )
    {
        $basePath = UrlManager::getBasePath($pathType);
        if( $templateName ) {
            $templatePath = $basePath .'/templates/blog/'. $this->themeName .'/'. $templateName;
        }
        else {
            $templatePath = $basePath .'/templates/blog/'. $this->themeName;
        }
        return $templatePath;
    }


}